package com.znsd.stu.controllor;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.znsd.entitys.Cwj_ClassInfo;
import com.znsd.entitys.Cwj_SpecialtyInfo;
import com.znsd.entitys.Users;
import com.znsd.stu.service.Cwj_ClassService;
import com.znsd.stu.service.Cwj_SpecialtyService;

@Controller
public class Cwj_SpecialtyControllor {
	@Autowired
	private Cwj_SpecialtyService Specialty;
	@Autowired
	private Cwj_ClassService classservice;
	
	@RequestMapping(value = "gospecialty", method = RequestMethod.GET)
	public String gospecialty(HttpServletRequest  request) {
		return "admin/specialty";
	}
	@ResponseBody
	@RequestMapping("specialtyList")
	public Map<String,Object> specialtyList(HttpServletRequest  request) {
		Map<String,Object> map=new HashMap<String,Object>();
		List<Cwj_SpecialtyInfo> list=Specialty.getAll();
		int count=Specialty.getCount();
		map.put("rows",list);
		map.put("total",count);
		return map;
	}
	@RequestMapping(value = "goSpecialtyDit", method = RequestMethod.GET)
	public String goSpecialtyDit(HttpServletRequest  request) {
		return "admin/specialtyadd";
	}
	@RequestMapping(value = "updateSpe", method = RequestMethod.POST)
	public String updateSpe(Integer hiddenId,String specialty_name,Integer state,HttpServletRequest  request) {
		Specialty.update(hiddenId, specialty_name, state);
		return "admin/specialty";
	}
	@RequestMapping(value = "addSpe", method = RequestMethod.POST)
	public String addSpe(String specialty_name,Integer state,HttpServletRequest  request) {
		HttpSession session=request.getSession();
		Users user=(Users) session.getAttribute("user");
		Specialty.insert(specialty_name, new Date(),user.getUser_id(), state);
		return "admin/specialty";
	}
	@RequestMapping(value = "SpeSave", method = RequestMethod.GET)
	public String SpeSave(Integer sId,HttpServletRequest  request) {
		//SpecialtyInfo spe=Specialty.checkId(sId);
		HttpSession session=request.getSession();
		session.setAttribute("sId",sId);
		return "admin/specialtyupdate";
	}
	
	@ResponseBody
	@RequestMapping("getSpe")
	public Map<String,Object> getSpe(HttpServletRequest  request) {
		//SpecialtyInfo spe=Specialty.checkId(sId);
		HttpSession session=request.getSession();
		Integer Sid=(Integer) session.getAttribute("sId");
		Cwj_SpecialtyInfo spe=Specialty.checkId(Sid);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("spe",spe);
		return map;
	}
	
	@ResponseBody
	@RequestMapping("getClassBySpe")
	public Map<String,Object> getClassBySpe(Integer sid,HttpServletRequest  request) {
		List<Cwj_ClassInfo> list=classservice.getBySpe(sid);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("size",list.size());
		return map;
	}
	@ResponseBody
	@RequestMapping("delSpe")
	public Map<String,Object> delSpe(Integer sid) {
		Specialty.delete(sid);
		Map<String,Object> map=new HashMap<String,Object>();
		return map;
	}
}
